package com.mikufufu.blog.controller.api;

import com.mikufufu.blog.common.entity.AjaxResult;
import com.mikufufu.blog.model.entity.User;
import com.mikufufu.blog.model.vo.api.UserVO;
import com.mikufufu.blog.security.utils.AuthUtils;
import com.mikufufu.blog.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@Api(tags = "客户端的用户接口")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/detail")
    @ApiOperation(value = "获取其他用户的详情", notes = "通过用户id查询指定用户的详细信息")
    @ApiImplicitParam(name = "id", value = "用户id", required = true)
    public AjaxResult<UserVO> detail(Integer id) {
        return AjaxResult.data(userService.getUserVOById(id));
    }

    @GetMapping("/info")
    @ApiOperation(value = "获取当前登录用户的详情", notes = "查看当前用户的数据")
    public AjaxResult<User> getUserInfo() {
        Integer id = AuthUtils.getUserId();
        User user = userService.getById(id);
        user.setPassword(null);
        return AjaxResult.data(user);
    }

}
